package com.manage.module.service.impl;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.manage.module.entity.Role;
import com.manage.module.entity.User;
import com.manage.module.mapper.RoleMapper;
import com.manage.module.service.RoleService;
import com.manage.utils.R;
import com.manage.utils.RequestSession;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 角色表 服务实现类
 * </p>
 *
 */
@Slf4j
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {

    @Override
    public R pageRole(Page page, Role role) {
        return new R(this.page(page, Wrappers.<Role>query().lambda().eq(Role::getDelFlag,"0")));
    }

    @Override
    public R queryRoleById(String id) {
        return new R(this.getById(id));
    }

    @Override
    public R saveRole(Role role) {
        RequestSession requestSession = new RequestSession();
        User user = requestSession.getUser();
        role.setCreateId(user.getId());
        role.setCreateName(user.getUsername());
        this.save(role);
        log.info("新增角色成功");
        return new R(true);
    }

    @Override
    public R updateRole(Role role) {
        this.updateById(role);
        log.info("更新角色成功");
        return new R(true);
    }

    @Override
    public R deleteRole(Role role) {
        role.setDelFlag("-1");
        this.updateById(role);
        log.info("删除角色成功");
        return new R(true);
    }
}
